<template>
  <div class="create-group-wrap">
    <el-form
      ref="form"
      label-position="left"
      :model="form"
      label-width="130px"
      class="form-wrap"
    >
      <div class="step-form-card" v-if="$attrs.active == 0">
        <div class="card-title">二维码设置</div>
        <div class="card-content">
          <el-form-item label="活码名称：">
            <el-input v-model="form.name" class="card-input" size="small"/>
          </el-form-item>
          <el-form-item label="活码LOGO：">
            <el-upload
              v-model="form.imageUrl"
              class="create-avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="form.groupLogo" :src="form.imageUrl" class="avatar"/>
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
            <div class="upload-tips">上传品牌LOGO，图片小于2M （选填）</div>
          </el-form-item>
        </div>
      </div>
      <div class="step-form-card" v-if="$attrs.active == 1">
        <div class="card-title">落地页设置</div>
        <div class="card-content">
          <el-form-item label="活动模式：">
            <el-radio-group v-model="form.mode">
              <el-radio-button label="0" border>页面模式</el-radio-button>
              <el-radio-button label="1" border>海报模式</el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="页面标题：">
            <el-input v-model="form.name" placeholder="请输入标题，必填" class="card-input" size="small"/>
          </el-form-item>
          <div v-if="form.mode == 1">
            <el-form-item label="海报：">
              <el-upload
                v-model="form.imageUrl"
                class="create-avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img v-if="form.logo" :src="form.imageUrl" class="avatar"/>
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
              <div class="upload-tips">
                1. 图片大小不超过2M<br/>
                2.海报图设计的时候请预留好二维码的位置<br/>
                3.可自行拖动二维码的位置和大小<br/>
              </div>
            </el-form-item>
          </div>
          <div v-else>
            <el-form-item label="群名称：">
              <el-checkbox v-model="form.checked">显示</el-checkbox>
              <div>
                <el-input
                  v-model="form.group_name"
                  class="card-input"
                  size="small"
                />
              </div>
              <div class="upload-cover-content">
                <el-upload
                  v-model="form.imageUrl"
                  class="small-avatar-uploader"
                  action="https://jsonplaceholder.typicode.com/posts/"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload"
                >
                  <img
                    v-if="form.imageUrl"
                    :src="form.imageUrl"
                    class="avatar"
                  />
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
                <div class="upload-tips">上传示例群头像图片，大小2M内</div>
              </div>
            </el-form-item>
            <el-form-item label="二维码LOGO：">
              <el-upload
                v-model="form.imageUrl"
                class="create-avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img v-if="form.logo" :src="form.imageUrl" class="avatar"/>
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
              <div class="upload-tips">上传品牌LOGO，图片小于2M</div>
            </el-form-item>
            <el-form-item label="辅助文案：">
              <el-input
                v-model="form.name"
                placeholder="辅助文案"
                class="card-input"
                size="small"
              />
            </el-form-item>
            <div class="mrore-setting-divider">
              <div class="divider-inner-text" @click="onHandleTiggerMore()">
                <div class="down-round-line">
                  <i
                    :class="[
                      'down-icon',
                      isMore ? 'el-icon-arrow-up' : 'el-icon-arrow-down',
                    ]"
                  />
                </div>
                <span class="more-text"
                >{{ isMore ? "收起" : "展开" }}更多设置</span
                >
              </div>
            </div>
            <div
              class="more-config"
              :style="{ height: !isMore ? '0px' : '428px' }"
            >
              <el-form-item label="客服二维码：">
                <el-upload
                  v-model="form.imageUrl"
                  class="create-avatar-uploader"
                  action="https://jsonplaceholder.typicode.com/posts/"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload"
                >
                  <img
                    v-if="form.logo"
                    :src="form.serviceLogo"
                    class="avatar"
                  />
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
                <div class="upload-tips">请上传客服二维码，图片小于2M</div>
              </el-form-item>
              <el-form-item label="活动方LOG：">
                <el-upload
                  v-model="form.imageUrl"
                  class="create-avatar-uploader"
                  action="https://jsonplaceholder.typicode.com/posts/"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload"
                >
                  <img v-if="form.logo" :src="form.imageUrl" class="avatar"/>
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
                <div class="upload-tips">上传活动方LOGO，大小2M内</div>
              </el-form-item>
              <el-form-item label="活动方名称：">
                <el-input
                  v-model="form.name"
                  placeholder="请输入"
                  class="card-input"
                  size="small"
                />
              </el-form-item>
              <el-form-item label="描述：">
                <el-input
                  v-model="form.name"
                  placeholder="请输入"
                  class="card-input"
                  size="small"
                />
              </el-form-item>
            </div>
          </div>
        </div>
      </div>
      <div class="step-form-card" v-if="$attrs.active == 2">
        <div class="card-title">群规则设置</div>
        <div class="card-content">
          <div class="card-column-item">
            <div class="head-top-content">
              <span class="title">手动选择群</span>
            </div>
            <el-form-item label="选择现有群：">
              <el-button icon="el-icon-plus" plain size="small" @click="getBlackByGroup"
              >客户群
              </el-button
              >
            </el-form-item>
          </div>
          <div class="card-column-item">
            <div class="head-top-content">
              <el-checkbox/>
              <span class="title" style="margin-left: 8px">自动建新群</span>
            </div>
            <el-form-item label="建群号：">
              <el-button icon="el-icon-plus" plain size="small"
              >企微号
              </el-button
              >
              <ul class="userBig">
                <li>
                  <div class="li-left">
                    <span>建群号1:</span><img src="@/assets/images/profile.jpg"/>
                  </div>
                  <div class="li-right">
                    <div class="title">新建群固定成员：</div>
                    <div class="group-btn">
                      <el-button size="small" @click="getAddBlackByUser"><i class="el-icon-plus"></i>选择客户</el-button>
                      <el-button size="small" @click="getChooseCompanyUser"><i class="el-icon-plus"></i>选择企业成员</el-button>
                      <div class="group-number">已选：<span>1</span>可选（39）</div>
                    </div>
                    <div class="user-list">
                      <h4>已选客户：</h4>
                      <img src="@/assets/images/profile.jpg"/>
                      <img src="@/assets/images/profile.jpg"/>
                    </div>
                    <div class="user-list">
                      <h4>已选成员：</h4>
                      <img src="@/assets/images/profile.jpg"/>
                      <img src="@/assets/images/profile.jpg"/>
                    </div>
                  </div>
                </li>
                <li>
                  <div class="li-left">
                    <span>建群号2:</span><img src="@/assets/images/profile.jpg"/>
                  </div>
                  <div class="li-right">
                    <div class="title">新建群固定成员：</div>
                    <div class="group-btn">
                      <el-button size="small"><i class="el-icon-plus"></i>选择客户</el-button>
                      <el-button size="small"><i class="el-icon-plus"></i>选择企业成员</el-button>
                      <div class="group-number">已选：<span>1</span>可选（39）</div>
                    </div>
                    <div class="user-list">
                      <h4>已选客户：</h4>
                      <img src="@/assets/images/profile.jpg"/>
                      <img src="@/assets/images/profile.jpg"/>
                    </div>
                    <div class="user-list">
                      <h4>已选成员：</h4>
                      <img src="@/assets/images/profile.jpg"/>
                      <img src="@/assets/images/profile.jpg"/>
                    </div>
                  </div>
                </li>

              </ul>
            </el-form-item>
            <el-form-item label="群名规则：">
              <div class="editor-wrap">
                <div class="editor-toolbar">
                  <div class="btn-num">编号</div>
                  <div class="start-num">
                    编号从
                    <el-input
                      size="small"
                      style="width: 58px; margin: 0 4px"
                    />
                    开始
                  </div>
                </div>
                <div class="editor-content">
                  <quill-editor
                    :options="editorOption"
                    style="min-height: 100px"
                    v-model="content"
                  />
                </div>
              </div>
            </el-form-item>
            <el-form-item label="触发建群：">
              <div>
                当可分配群少于
                <el-input
                  style="width: 88px; margin: 0 8px"
                  size="small"
                />
                个时，开始建群
              </div>
            </el-form-item>
            <el-form-item label="自动打群标签：">
              <el-checkbox v-mode="form.close">已关闭</el-checkbox>
            </el-form-item>
          </div>
          <div class="card-column-item">
            <div class="head-top-content">
              <span class="title">群规则</span>
            </div>
            <el-form-item>
              <div slot="label">
                群成员上限
                <el-tooltip
                  style="margin-left: 4px; color: #666"
                  effect="dark"
                  placement="top"
                >
                  <div slot="content">
                    超出200人的群不能扫码加入，扫码页<br/>不会展示
                  </div>
                  <svg-icon icon-class="iquestion"/>
                </el-tooltip
                >
                ：
              </div>
              <el-input style="width: 98px"/>
            </el-form-item>
            <el-form-item>
              <div slot="label">
                群展示顺序
                <el-tooltip
                  style="margin-left: 4px; color: #666"
                  effect="dark"
                  placement="top"
                >
                  <div slot="content">
                    有多个企微号（需登录企微宝云端<br/>版）在同一个群内时，每个号都会获<br/>取该群的群二维码，进行随机展示，<br/>即由多个邀请者邀请入群，避免单个<br/>号拉人过于频繁。
                  </div>
                  <svg-icon icon-class="iquestion"/>
                </el-tooltip
                >
                ：
              </div>
              <el-radio-group v-model="form.radio">
                <el-radio :label="0">所有群轮流展示</el-radio>
                <el-radio :label="1">群满员后，展示下一个群</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item>
              <div slot="label">
                群展示顺序
                <el-tooltip
                  style="margin-left: 4px; color: #666"
                  effect="dark"
                  placement="top"
                >
                  <div slot="content">
                    有多个企微号（需登录企微宝云端<br/>版）在同一个群内时，每个号都会获<br/>取该群的群二维码，进行随机展示，<br/>即由多个邀请者邀请入群，避免单个<br/>号拉人过于频繁。
                  </div>
                  <svg-icon icon-class="iquestion"/>
                </el-tooltip
                >
                ：
              </div>
              <el-checkbox v-mode="form.isOpen">已开启</el-checkbox>
            </el-form-item>
          </div>
        </div>
      </div>
      <div class="preview-wrap" v-if="$attrs.active == 1">
        <div class="preview-title">扫码页预览</div>
        <div class="preview-mobile-content">
          <div class="mobile-nav-bar">
            <div class="nav-bar-title">标题</div>
          </div>
          <!--        海报模式-->
          <div class="preview-content" style="height: 640px; padding: 0; position: relative; width:356px;" v-if="form.mode == 1">
            <vue-drag-resize
              :isActive="true"
              :w="200"
              :h="200"
              :parentLimitation="true"
              :aspectRatio="true"
              @resizing="resize"
              @dragging="resize"
            >
              <div class="code">二维码</div>
            </vue-drag-resize>
          </div>
          <!--          页面模式-->
          <div class="preview-content" v-if="form.mode == 0">
            <div class="qrcode-box">
              <div class="group-big">
                <div class="group-img"><img src="https://cdn-qyb-hz.wxb.com/u/5424982/qyb/20240318/1add7dd7c8b1b4309432f879f6cd28b2.jpg"/></div>
                <div class="group-name">群名称</div>
              </div>
              <div class="qrcode">
                <img
                  class="cover"
                  src="https://cdn-qyb-hz.wxb.com/u/5424982/qyb/20240318/1add7dd7c8b1b4309432f879f6cd28b2.jpg"
                />
              </div>
              <div class="auxiliaryText">这是辅助文字,这是辅助文字</div>
              <div class="bottom-text">若无法识别可截屏保存后添加</div>
            </div>
          </div>
        </div>
        <div class="prewiew-tips" v-if="form.mode == 0">
          注：此处的二维码只是预览效果，切勿直接使用
        </div>
      </div>
    </el-form>
    <!--    从客户群添加-->
    <addBlackByGroup v-if="showAddBlackByGroup" :visableIf.sync="showAddBlackByGroup"></addBlackByGroup>
<!--    添加客户-->
    <addBlackByUser v-if="showAddBlackByUser" :visableIf.sync="showAddBlackByUser"></addBlackByUser>
<!--    从企业成员添加-->
    <chooseCompanyUser v-if="showChooseCompanyUser" :visableIf.sync="showChooseCompanyUser"></chooseCompanyUser>
  </div>
</template>
<script>
import {quillEditor} from "vue-quill-editor";
import Vue from 'vue'
import VueDragResize from 'vue-drag-resize'
Vue.component('vue-drag-resize', VueDragResize)
export default {
  data() {
    return {
      showAddBlackByGroup: false,
      showAddBlackByUser: false,
      showChooseCompanyUser:false,
      stepList: ["基本设置", "扫码页设置", "群和规则设置"],
      isMore: false,
      form: {
        mode:0,
        imageUrl:
          "https://cdn.llxzl.com/goods/user/4/20200908/e39d825369deb1e717c789cd8bc5ea60.jpg",
      },
      isMousedown: false,
      dragging: false,
      x: 0,
      y: 0,
      styleObject: {
        position: 'absolute',
        top: '0',
        left: '0'
      },
      content: "",
      editorOption: {
        modules: {
          // 隐藏工具栏
          toolbar: false,
        },
        placeholder: "请输入内容",
      },
    };
  },
  components: {
    quillEditor,
    addBlackByGroup: () => import('./addBlackByGroup.vue'),
    addBlackByUser: () => import('./addBlackByUser.vue'),
    chooseCompanyUser:()=>import('./chooseCompanyUser.vue'),
  },
  methods: {
    resize(newRect) {
      this.width = newRect.width;
      this.height = newRect.height;
      this.top = newRect.top;
      this.left = newRect.left;
    },
    getBlackByGroup() {
      this.showAddBlackByGroup = true;
    },
    getChooseCompanyUser(){
      this.showChooseCompanyUser=true;
    },
    getAddBlackByUser() {
      this.showAddBlackByUser = true;
    },
    handleAvatarSuccess(res, file) {
      this.form.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    onHandleTiggerMore() {
      this.isMore = !this.isMore;
    },


  },
};
</script>
<style lang="scss" scoped>
.create-group-wrap {
  padding: 16px 16px 76px;

  .form-wrap {
    display: flex;
    padding: 0 80px;

    .step-form-card {
      display: inline-block;
      flex: 1 1;
      text-align: left;
      text-align: initial;
      color: rgba(0, 0, 0, 0.85);
      border-radius: 4px;
      background: #fff;
      font-size: 14px;

      .card-title {
        padding: 16px;
        font-weight: 600;
        color: rgba(0, 0, 0, 0.85);
      }

      .card-content {
        border-top: 1px solid #f5f5f5;
        padding: 24px;

        .card-input {
          width: 400px;
        }

        .upload-cover-content {
          margin-top: 8px;

          .small-avatar-uploader {
            width: 102px;
            height: 102px;

            .avatar {
              width: 102px;
              height: 102px;
            }
          }

          .upload-tips {
            margin-top: 8px;
            font-size: 14px;
            line-height: 22px;
            color: rgba(0, 0, 0, 0.45);
          }
        }

        .mrore-setting-divider {
          color: rgba(0, 0, 0, 0.65);
          font-weight: 400;
          font-size: 14px;
          display: flex;
          margin: 16px 0;
          white-space: nowrap;
          text-align: center;
          border-top: 0;
          border-top-color: rgba(0, 0, 0, 0.06);

          &::before {
            position: relative;
            top: 50%;
            width: 50%;
            border-top: 1px solid transparent;
            border-top-color: inherit;
            border-bottom: 0;
            transform: translateY(50%);
            content: "";
          }

          &::after {
            position: relative;
            top: 50%;
            width: 50%;
            border-top: 1px solid transparent;
            border-top-color: inherit;
            border-bottom: 0;
            transform: translateY(50%);
            content: "";
          }

          .divider-inner-text {
            padding: 0 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;

            .down-round-line {
              width: 14px;
              height: 14px;
              display: flex;
              align-items: center;
              justify-content: center;
              border-radius: 50%;
              border: 1px solid rgba(0, 0, 0, 0.65);

              .down-icon {
                font-size: 10px;
              }
            }

            .more-text {
              margin-left: 8px;
            }
          }
        }

        .more-config {
          height: 428px;
          overflow: hidden;
          transition: height 0.3s;
        }

        .card-column-item {
          position: relative;
          margin-bottom: 20px;

          &::before {
            content: "";
            width: 3px;
            height: 14px;
            display: block;
            background: #3070ff;
            position: absolute;
            top: 13px;
            left: 0;
          }

          .head-top-content {
            margin-bottom: 20px;
            padding: 9px 12px;
            background: #f5f5f5;
            border-radius: 4px;
            font-size: 16px;
            font-family: PingFangSC-Semibold, PingFang SC;
            font-weight: 600;
            color: rgba(0, 0, 0, 0.85);
          }
        }
      }
    }

    .create-avatar-uploader {
      .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 104px;
        height: 104px;
        line-height: 104px;
        text-align: center;
      }

      .avatar {
        width: 104px;
        height: 104px;
        display: block;
      }
    }

    .upload-tips {
      font-size: 14px;
      line-height: 22px;
      color: rgba(0, 0, 0, 0.45);
    }

    .preview-wrap {
      width: 388px;
      background: #fff;
      border-radius: 0 4px 4px 0;
      padding: 16px;
      border-left: 1px solid #ececec;

      .preview-title {
        padding: 0px;
        font-size: 16px;
        font-weight: 600;
        color: rgba(0, 0, 0, 0.85);
        margin-bottom: 30px;
      }

      .preview-mobile-content {
        margin-bottom: 16px;
        border-radius: 6px;
        overflow: hidden;
        text-align: center;
        position: relative;

        .mobile-nav-bar {
          height: 70px;
          background: url("../../../../../assets/images/pic_mobile_head_bar.png") no-repeat 50% / cover;

          .nav-bar-title {
            padding: 40px 60px 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            color: rgba(0, 0, 0, 0.65);
            font-size: 14px;
            font-weight: 500px;
            line-height: 22px;
          }
        }

        .preview-content {
          padding: 20px;
          background: #f4f6fe;

          .qrcode-box {
            background: #fff;
            box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.05);
            border-radius: 6px;
            padding: 20px 20px 32px;
            position: relative;

            .group-big {
              position: absolute;
              left: 20px;
              top: 20px;
              display: flex;
              align-items: center;
              justify-content: center;

              .group-img {
                width: 40px;
                height: 40px;
                border-radius: 4px;

                img {
                  width: 40px;
                  height: 40px;
                  border-radius: 4px;
                  margin-right: 10px;
                }
              }

              .group-name {
                font-weight: bold;
                font-size: 14px;
                margin-left: 10px;
              }
            }

            .qrcode {
              width: 200px;
              height: 200px;
              margin-top: 80px;
              margin-left: auto;
              margin-right: auto;
              background: url("../../../../../assets/images/pic_mobile_qrcode.png") no-repeat 50% / cover;
              display: flex;
              align-items: center;
              justify-content: center;

              .cover {
                width: 42px;
                height: 42px;
                background: #fff;
                border-radius: 4px;
              }
            }
          }

          .auxiliaryText {
            color: rgba(0, 0, 0, 0.45);
            font-size: 14px;
            margin-top: 20px;
            margin-bottom: 2px;
          }

          .bottom-text {

            color: rgba(0, 0, 0, 0.45);
            font-size: 14px;
            line-height: 22px;
          }
        }

        .preview-content-drag-mode {
          background-color: #f4f6fe;
          background-repeat: no-repeat;
          background-size: 100%;
          height: calc(100vh - 370px);
          position: relative;

          .drag-box {
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #fff;
            border: 1px dashed #e9e9e9;
            height: 81px;
            width: 81px;
            cursor: move;
            position: absolute;
            top: 0px;
            left: 0px;
          }
        }
      }

      .prewiew-tips {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.45);
        font-weight: 400;
        text-align: center;
      }
    }
  }
}

.editor-wrap {
  width: 400px;
  border: 1px solid #ececec;

  .editor-toolbar {
    padding: 8px;
    font-size: 14px;
    line-height: 22px;
    background: #f9f9f9;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .btn-num {
      background: #fff;
      border: 1px solid #e9e9e9;
      padding: 3px 8px;
      cursor: pointer;
      margin: 0;
      border-radius: 2px;
      color: #666;
    }
  }

  ::v-deep .editor-content .ql-snow {
    border: none;
  }
}

.userBig {
  border: 1px solid #eee;
  margin-top: 10px;

  li {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    border-radius: 4px;
    padding: 0 12px;
    color: rgba(0, 0, 0, .65);
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 10px;

    .li-left {
      display: flex;
      width: 120px;
      padding-top: 16px;

      span {
        margin-right: 10px;
      }

      img {
        width: 32px;
        height: 32px;
        border-radius: 4px;
      }
    }

    .li-right {
      border-left: 1px solid #eee;
      padding-left: 15px;
      margin-left: 15px;

      .group-btn {
        display: flex;
        height: 32px;
        margin-bottom: 10px;

        .group-number {
          margin-left: 10px;
        }
      }

      .user-list {
        display: flex;
        height: 50px;
        display: flex;
        align-items: center;
        border: 1px solid #eee;
        padding: 10px;
        border-radius: 4px;
        margin-bottom: 10px;

        h4 {
          font-weight: 400;
          margin: 0px;
        }

        img {
          width: 32px;
          height: 32px;
          border-radius: 4px;
          margin-right: 10px;
        }


      }
    }
  }
}
.code {
  font-size: 12px;
  color: #888;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}
</style>
